import request from '../../utils/request'

/**
 * 查询客户列表
 *
 * @param appCode
 * @returns {Promise.<Object>}
 */
export async function queryCustomers({ customerNO, cstName, cstType, cstManage, cstWaiter, status, certificationStatus, page, beginTime, endTime, businessType }) {
    return request(apiPath.mc + "/api/customer", {
        method: 'get',
        data: { customerNO, cstName, cstType, cstManage, cstWaiter, status, certificationStatus, page: page.page, size: page.size, beginTime, endTime, businessType }
    });
}

/**
 * 创建客户
 *
 * @param params
 * @returns {Promise.<void>}
 */
export async function createCustomer({ companyname, companynameen, shortname, ischeckinfo, companytype, businessmodel, telephone, mobile, tax, email, address, addressen, recaddress, url, invoicetype, businessType, autoSync, taxId, capital, capitalcurrency, registerdate, taxpayerid, orgcode, customsregno, entperson, bussiregno }) {
    return request(apiPath.mc + "/api/customer", {
        method: 'post',
        data: { companyname, companynameen, shortname, ischeckinfo, companytype, businessmodel, telephone, mobile, tax, email, address, addressen, recaddress, url, invoicetype, businessType, autoSync, taxId, capital, capitalcurrency, registerdate, taxpayerid, orgcode, customsregno, entperson, bussiregno }
    });
}

/**
 * 修改客户基本信息
 *
 * @param params
 * @returns {Promise.<void>}
 */
export async function updateCustomerBase({
                                             id, companyname, companynameen, shortname, ischeckinfo, status, companytype, businessmodel, telephone, mobile, tax, email, invoicetype, address, addressen, recaddress, url, industry,
    subindustry, mainproduct, settlement, lastexports, premonthexportamount, entrust, businessType, exportcountry, fkmanager, manager, waiter,
    tgmanager, capital, capitalcurrency, registerdate, bussiregno, taxpayerid, orgcode, customsregno, entperson, csttype
                                         }) {
    return request(apiPath.mc + "/api/customer", {
        method: 'put',
        data: {
            id, companyname, companynameen, shortname, ischeckinfo, status, companytype, businessmodel, telephone, mobile, tax, email, invoicetype, address, addressen, recaddress, url, industry,
            subindustry, mainproduct, settlement, lastexports, premonthexportamount, entrust, exportcountry, fkmanager, manager, waiter,
            tgmanager, capital, capitalcurrency, registerdate, bussiregno, taxpayerid, orgcode, customsregno, entperson, csttype, businessType
        }
    });
}

/**
 * 市场采购
 * 修改客户信息--基本信息
 *
 * @param params
 * @returns {Promise.<void>}
 */
export async function updateMpCustomerBase(data) {
    return request(apiPath.mc + "/api/mpcustomer", {
        method: 'put',
        data
    });
}


/**
 * 根据id获取客户信息
 * @param id
 * @returns {Promise.<void>}
 */
export async function getCustomerById({ id, isApproval }) {
    return request(apiPath.mc + "/api/customer/" + id, {
        method: 'get',
        data: { isApproval }
    });
}



/**
 * 删除客户
 * @param id
 * @returns {Promise.<void>}
 */
export async function deleteCustomerById({ id }) {
    return request(apiPath.mc + "/api/customer/" + id, {
        method: 'delete'
    });
}

/**
 * 客户审核
 * @param cstid
 * @param approvalresult
 * @param approvalmemo
 * @returns {Promise.<void>}
 */
export async function approvalCustomer({ cstid, approvalresult, approvalmemo }) {
    let businesstype = "customer";
    let entityid = cstid;
    return request(apiPath.mc + "/api/customer/" + cstid + "/approval", {
        method: 'post',
        data: { approvalresult, approvalmemo, businesstype, entityid }
    });
}

/**
 * 修改协议信息
 * @param dataSource
 * @returns {Promise.<void>}
 */
export async function entqualification({ form }) {
    return request(apiPath.mc + "/api/customer/entqualification", {
        method: 'put',
        data: { ...form }
    });
}

/**
 * 查询客户未结算的订单
 * @param cstId
 * @returns {Promise.<void>}
 */
export async function getUnsettleorder({ cstId }) {
    return request(apiPath.mc + "/api/customer/" + cstId + "/unsettleorder", {
        method: 'get',
    });
}

/**
 * 获取历史余额列表
 * @param cstId
 * @returns {Promise.<void>}
 */
export async function getHistoryAmtList({ cstId }) {
    return request(apiPath.mc + "/api/customer/" + cstId + "/historyamt", {
        method: 'get',
    });
}

/**
 * 获取结算详情
 * @param type
 * @param cstId
 * @param orderIds
 * @returns {Promise.<void>}
 */
export async function getStatetemntDetail({ type, cstId, orderIds }) {
    return request(apiPath.mc + "/api/statement/" + type + "/detail", {
        method: 'get',
        data: { type, cstId, orderIds }
    });
}


/**
 * 获取审核记录
 * @param cstId
 * @returns {Promise.<void>}
 */
export async function getApprovaList({ cstId }) {
    return request(apiPath.mc + "/api/customer/" + cstId + "/approval", {
        method: 'get',
    });

}


/**
 * 根据name or code获取客户信息
 * @param id
 * @returns {Promise.<void>}
 */
export async function getCustomerByNameOrCode({ nameOrCode }) {
    return request(apiPath.mc + "/api/customer/nc", {
        method: 'get',
        data: { nameOrCode }
    });

}

/**
 * 查询银企直联数据列表
 *
 */
export async function queryCustomerBanks({ customerNo, bankId, cstName, beginTime, endTime, page }) {
    return request(apiPath.mc + "/api/customer/bank", {
        method: 'get',
        data: { customerNo, bankId, cstName, beginTime, endTime, page: page.page, size: page.size }
    });
}

/**
 * 创建银企直联子账号
 *
 * @param params
 */
export async function createBankSubAccount(data) {
    return request(apiPath.mc + "/api/customer/bank", {
        method: 'post',
        data
    });
}

/**
 * 子账号结汇申请
 *
 * @param params
 */
export async function applyConversion({ id }) {
    return request(apiPath.mc + "/api/customer/" + id + "/conversion", {
        method: 'post'
    });
}

/**
 * 更新银企直联子账号
 *
 * @param params
 */
export async function updateBankSubAccount(data) {
    return request(apiPath.mc + "/api/customer/bank", {
        method: 'put',
        data
    });
}

/**
 * 获取银企直联子账号
 *
 * @param params
 */
export async function getBankSubAccount({ id }) {
    return request(`${apiPath.mc}/api/customer/bank/${id}`, {
        method: 'get'
    });
}

export async function createCustomerExtra(data) {
    return request(`${apiPath.mc}/api/customer/extra`, {
        method: 'post',
        data
    });
}

export async function updateCustomerExtra(data) {
    return request(`${apiPath.mc}/api/customer/extra`, {
        method: 'put',
        data
    });
}

/**
 * 开设工厂用户账号
 * @param data 
 */
export async function createFactotyCustomer(data) {
    return request(`${apiPath.mc}/api/factoty/customer`, {
        method: 'post',
        data
    })
}

/**
 * 修改官网认证企业审核状态
 * @param {*} data 
 */
export async function updateWebsiteCompany(data) {
    return request(`${apiPath.mc}/api/customer`, {
        method: 'put',
        data
    });
}

//一键同步企业信息
export async function autoSync(data) {
    return request(`${apiPath.mc}/api/customer/autoSync`, {
        method: 'get',
        data
    });
}